<?php
/**
 * Created by PhpStorm.
 * User: LiuJiaJun
 * Date: 2019/1/13
 * Time: 22:58
 */

namespace api\storage\model;


use think\Model;

class OutflowModel extends Model
{
    protected $table = 'iwh_outflow';
    protected $pk = 'uuid';

    /**
     * 增加出库流水数据
     *
     * @param $data
     * @return false|int
     */
    public function add($data){
        return $this->save($data);
    }
    /**
     * 添加批量数据
     *
     * @param $data
     * @return array|false
     * @throws \Exception
     */
    public function addAll($data){
        return $this->saveAll($data);
    }

    /**
     * 获取出库流水数据
     *
     * @param $orderId
     * @param $fentryId
     * @param $storageUuid
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function queryOutflow($orderId,$fentryId,$storageUuid){
        $where['order_id'] = $orderId;
        if(!empty($fentryId)){
            $where['fentryid'] = $fentryId;
        }
        $where['storage_uuid'] = $storageUuid;
        return $this->where($where)->select();
    }

    public function queryOutflowByWhere($where){
        return $this->alias('a')
            ->join(['iwh_sub_materiel'=>'b'],'a.sub_materiel_id = b.sub_materiel_id','left')
            ->field('a.reel_id,a.sub_materiel_id,a.count,b.shelves_type as type,a.order_id,a.fentryid,b.sub_materiel_name')
            ->where($where)
            ->order('a.sub_materiel_id,a.reel_id,b.shelves_type')
            ->select();
    }
}